cap program drop DW_bycomp_combined

program define DW_bycomp_combined

syntax varlist, ctrls(string) newctrls(string) outcome(string) xmin(string) xmax(string) xdelta(string) wave(string)

	foreach depvar in `varlist' {

	local depvar `depvar'
	local ctrls `ctrls'
	local newctrls `newctrls'
	local condition `condition'
	local outcome `outcome'
	local xmin `xmin'
	local xmax `xmax'
	local xdelta `xdelta'
	local wave `wave'

		reg `depvar' treat_control_dw_study2 `ctrls' if forced_type==0 & treat_control_sbd_study2==0
			margins, dydx(treat_control_dw_study2)
				matrix `depvar'_DW = r(table)
					matselrc `depvar'_DW `depvar'_DW, r(1, 5, 6) c(1)
		
		reg `depvar' treat_dw_hom_blue treat_dw_mix `ctrls2' if forced_type==0 & forced_comp==0 & treat_control_sbd_study2==0
			margins, dydx(treat_dw_hom_blue treat_dw_mix)
				matrix `depvar' = r(table)
					matselrc `depvar' `depvar'_hom, r(1, 5, 6) c(1)
					matselrc `depvar' `depvar'_mix, r(1, 5, 6) c(2)

				graph set window fontface "Times"
				coefplot (matrix(`depvar'_DW[1,]), ci((`depvar'_DW[2,] `depvar'_DW[3,])) recast(scatter) ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square)) ///
					(matrix(`depvar'_hom[1,]), ci((`depvar'_hom[2,] `depvar'_hom[3,])) recast(scatter) ciopts(lcolor(black) lpattern(longdash)) mcolor(black) msymbol(circle)) ///
					(matrix(`depvar'_mix[1,]), ci((`depvar'_mix[2,] `depvar'_mix[3,])) recast(scatter) ciopts(lcolor(black) lpattern(shortdash)) mcolor(black) msymbol(triangle)), ///
						name(`depvar', replace) scheme(plotplain) ///
						xtitle("Treatment effect on `outcome'", margin(medsmall)) xlabel(`xmin'(`xdelta')`xmax', nogrid) ///
						coeflabels(treat_control_dw_study2 = "Any DW" treat_dw_hom_blue = "Homogeneous DW" treat_dw_mix = "Mixed DW") offset(0) ///
						ytick(1.5, notick glpattern(solid) glcolor(gray)) ///
						xline(0, lcolor(black) lpattern(dash)) ///
						legend(off) ///
						title("", margin(medsmall))

				graph export "Output/`depvar'_DW_bycomp_combined_`wave'.pdf", as(pdf) replace
				cap graph export "$dir_Overleaf/Figures/`depvar'_DW_bycomp_combined_`wave'.pdf", as(pdf) replace
				cap graph export "$dir_Overleaf_JG/Figures/`depvar'_DW_bycomp_combined_`wave'.pdf", as(pdf) replace
	
	
	
	}
	
end
		
		
